package org.coldlife.sim.grav;

import javax.vecmath.Vector3d;

public class MassParitcle extends Particle 
{
	private double mass;
	private Vector3d netForce;

	public MassParitcle() 
	{
		this.mass = 1;
		this.netForce=new Vector3d();
	}
	/**
	 * Adds a force to the netForce this particle is experiencing.
	 * @param force
	 */
	public void applyForce(Vector3d force)
	{
		getNetForce().add(force);
	}
	
	@Override
	public void updatePosition(double t) 
	{
		if(t==0) return;
		
		accelerate(getNetForce(), t);
		super.updatePosition(t);
	}
	
	public void accelerate(Vector3d force,double time)
	{
		Vector3d impulse = new Vector3d(force);
		impulse.scale(time);
		
		accelerate(impulse);
	}
	
	/**
	 * Updates this particle's velocity.
	 * @param impulse an force applied over time
	 */
	public void accelerate(Vector3d impulse)
	{
		Vector3d vf = new Vector3d(impulse);
		vf.scale(getMass());
		vf.add(getVelocity());
		
		setVelocity(vf);
	}

	public void resetForce()
	{
		netForce.scale(0);
	}
	
	public double getMass() {
		return mass;
	}

	public void setMass(double mass) {
		this.mass = mass;
	}

	public Vector3d getNetForce() {
		return netForce;
	}

	public void setNetForce(Vector3d force) {
		this.netForce = force;
	}
}
